const apiConf = require('./apiConf.env');

const axiosUrl = `http://${apiConf.host ? apiConf.host :'127.0.0.1'}:${apiConf.port}`;
module.exports = {
    /*
     ** Nuxt rendering mode
     ** See https://nuxtjs.org/api/configuration-mode
     */
    mode: 'universal',
    dev: process.env.NODE_ENV !== "production",
    /*
     ** Nuxt target
     ** See https://nuxtjs.org/api/configuration-target
     */
    // target: 'server',
    /*
     ** Headers of the page
     ** See https://nuxtjs.org/api/configuration-head
     */
    head: {
        title: "HopeTravel希望之旅",
        meta: [
            { charset: 'utf-8' },
            { name: 'viewport', content: 'width=device-width, initial-scale=1' },
            { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
        ],
        link: [
            { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
        ],
        script: [{
            src: '/flexible/flexible.js',
            type: 'text/javascript',
            charset: 'utf-8',
        }]
    },
    /*
     ** Global CSS
     */
    // css: ["@/assets/index.scss", "vant/lib/index.css"],
    /*
     ** Plugins to load before mounting the App
     ** https://nuxtjs.org/guide/plugins
     */
    plugins: [{
        src: '~plugins/vant',
        ssr: true
    }],
    /*
     ** Auto import components
     ** See https://nuxtjs.org/api/configuration-components
     */
    components: true,
    /*
     ** Nuxt.js dev-modules
     */
    buildModules: [],
    /*
     ** Nuxt.js modules
     */
    modules: [
        // Doc: https://axios.nuxtjs.org/usage
        '@nuxtjs/axios',
    ],
    /* router: {
        extendRoutes(routes, resolve) {
            // console.log(routes)
            routes.push({
                name: "error404",
                path: "*",
                component: resolve(__dirname, "pages/error.vue")
            });
        }
    }, */
    /*
     ** Axios module configuration
     ** See https://axios.nuxtjs.org/options
     */
    axios: {
        proxy: true,
        // prefix: '/api', // baseURL
        credentials: true,
        baseURL: axiosUrl // 本地接口请求配置
    },
    proxy: {
        "/api": {
            target: `${apiConf.base}:8001`,
            pathRewrite: {
                "^/api": '/'
            },
            changeOrigin: true
        }
    },
    server: {
        // 本地所起的服务配置
        host: apiConf.host || "127.0.0.1",
        port: apiConf.port
            // host: apiConfig.host,
    },
    /*
     ** Build configuration
     ** See https://nuxtjs.org/api/configuration-build/
     */
    build: {
        vendor: ['axios', 'vant']
    },
    buildDir: "dist"
}